package me.like.diandian.base;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import androidx.fragment.app.Fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import io.reactivex.disposables.CompositeDisposable;

/**
 * Created by shousakai on 2019/6/21.
 */

public abstract class BaseFragment<T extends ViewDataBinding> extends Fragment {
    protected T binding;
    protected BaseActivity activity;
    public CompositeDisposable mCompositeSubscription;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        activity =  (BaseActivity)getActivity();
        mCompositeSubscription = activity.mCompositeSubscription;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        binding = DataBindingUtil.inflate(LayoutInflater.from(getContext()),getLayoutId(),container,false);
        initView();
        return binding.getRoot();
    }
    protected abstract void initView();
    protected abstract int getLayoutId();


    protected void onClick(View view, io.reactivex.functions.Consumer consumer){
        activity.onClick(view,consumer);
    }



}
